/* 
 * File:   m_vektor.c
 * Author: n.kaminski
 *
 * Created on 1. Oktober 2012, 10:38
 */

#include <stdio.h>
#include <stdlib.h>
#include "m_vektor.h"

vektor createVektor(int length)
{ 
    vektor v = {NULL, 0};    
    
    v.content = malloc(length * sizeof(VEKTOR_CONTENT_TYPE));
    
    v.length = length;
    
    return v;
}

vektor createVektorWithArray(VEKTOR_CONTENT_TYPE a[], int l)
{  
    vektor v = {a, l};
    return v;
}

void swap(vektor v, int a, int b)
{
    VEKTOR_CONTENT_TYPE zw;
    zw = v.content[a];
    v.content[a] = v.content[b];
    v.content[b] = zw;
}

void sortiereVektoren(vektor a, vektor b)
{
    int newn;
    int i;
    int n = a.length;
    do{
        newn = 1;
        for(i = 0; i < n-1; ++i){
            if(a.content[i] > a.content[i+1]){
                swap(a, i, i+1);
                swap(b, i, i+1);
                newn = i+1;
            }
        }
        n = newn;        
    }while( n > 1);
}

void printVektor(vektor v)
{
    int i;
    for(i = 0; i < v.length; ++i){
        printf(VEKTOR_CONTENT_FORMAT, v.content[i]);
    }
    printf("\n");
}

